{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3f462f02",
   "metadata": {},
   "source": [
    "# 3.1 顺序查找；\n",
    "\n",
    "线性表查找"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f8325e40",
   "metadata": {},
   "outputs": [],
   "source": [
    " def search(self, nums: List[int], target: int) -> int:\n",
    "\n",
    "        if len(nums) == 0:\n",
    "            return -1\n",
    "\n",
    "        for i in range(len(nums)):\n",
    "            if nums[i] == target:\n",
    "                return i\n",
    "\n",
    "        return -1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d2ff9aca",
   "metadata": {},
   "source": [
    "# 3.2  二分查找"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f50fe3ba",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "20\n",
      "-1\n"
     ]
    }
   ],
   "source": [
    "arr =[2,5,6,8,12,15,17,23,27,31,39,40,45,56,79,90]\n",
    "l, r = 0, len(arr) - 1\n",
    "n = int(input())\n",
    "\n",
    "while l <= r:\n",
    "    mid = (l+r) // 2\n",
    "    \n",
    "    if arr[mid] < n:\n",
    "        l = mid + 1\n",
    "    elif arr[mid] > n:\n",
    "        r = mid - 1\n",
    "    else:\n",
    "        print(mid)\n",
    "        break\n",
    "        \n",
    "print(-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "08a3489d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "66\n",
      "13\n"
     ]
    }
   ],
   "source": [
    "arr =[2,5,6,8,12,15,17,23,27,31,39,40,45,56,79,90]\n",
    "l, r = 0, len(arr) - 1\n",
    "n = int(input())\n",
    "\n",
    "while l < r:\n",
    "    mid = (l+r + 1) // 2\n",
    "    \n",
    "    if arr[mid] <= n:\n",
    "        l = mid \n",
    "    else:\n",
    "        r = mid- 1\n",
    "        \n",
    "print(l)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "a54a8aa3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n"
     ]
    }
   ],
   "source": [
    "arr = [1,3,5,6]\n",
    "\n",
    "print(len(arr))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d413b731",
   "metadata": {},
   "source": [
    "# 3.3 树\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2e921087",
   "metadata": {},
   "source": [
    "# 3.4 二叉树"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a2d76b4d",
   "metadata": {},
   "source": [
    "# 3.5 二叉搜索树"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "004534f6",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3e03b551",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "trader",
   "language": "python",
   "name": "trader"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
